package com.ribbon.user;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCollapser;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.ribbon.User;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * Created by qhe on 2018/7/27.
 */
@Service
public class UserServiceA {


    @Autowired
    RestTemplate restTemplate;

    @HystrixCollapser(batchMethod = "findAll",collapserProperties = {
            @HystrixProperty(name="timerDelayInMilliseconds",value = "100")})
    public User find(Long id){return null;}


    @HystrixCommand
    public List<User> findAll(List<Long> ids){
        return restTemplate.getForObject("http://user-service/user?ids={1}",List.class, StringUtils.join(ids,","));
    }





























}
